import util.mydecorator
import util.lib as lib

import pandas as pd
from daily import get_daily_df

def lp_static(shares):

    ret = None

    for item in shares.iterrows():
        stock_name = item[1]['name']
        print(stock_name)
        df = get_daily_df(stock_name)[-750:]

        if ret is None:
            ret = df[['level_point']]
        ret[stock_name] = df['level_point']

    ret = ret.drop(['level_point'], axis=1)

    # 按日期倒序
    ret = ret[::-1]

    # 获取最近的周
    print("排序日：", ret.T.columns.tolist()[0])

    tmp = ret.T
    sortKey = tmp.columns.tolist()[0]
    tmp = tmp.sort_values(by=sortKey, ascending=False)

    return tmp.T

@util.mydecorator.calTime
def job():
    shares = lib.lib_get_all_stock()
    df = lp_static(shares)

    df.to_excel(lib.data_path + "daily_lp.xlsx")



if __name__ == "__main__":
    job()